package com.deparse.mydialog.listview;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

import com.deparse.mydialog.R;
import com.deparse.mydialog.common.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/22.
 */
public class BaseListActivity extends BaseActivity {

    private ListView listView;
    private MyBaseAdapter adapter;
    private List<String> listData = new ArrayList<>();
    private LayoutInflater layoutInflater;
    private TextView title;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_list);
        layoutInflater = LayoutInflater.from(this);
        listView = (ListView) findViewById(R.id.listView);
        title= (TextView) findViewById(R.id.title);
        for (int i = 0; i < 30; i++) {
            listData.add("text" + i);
        }
        adapter = new MyBaseAdapter();
        listView.setAdapter(adapter);
    }
    public TextView getListTitle() {
        return this.title;
    }
    public ListView getListView() {
        return this.listView;
    }

    public List<String> getListData() {
        return this.listData;
    }

    public MyBaseAdapter getAdapter() {
        return this.adapter;
    }


    public class MyBaseAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public Object getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = layoutInflater.inflate(R.layout.item_main_list, null);
            TextView activity_name = (TextView) convertView.findViewById(R.id.activity_name);
            CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.checkbox);

            activity_name.setText(listData.get(position));
            checkbox.setChecked(((ListView) parent).isItemChecked(position));
            return convertView;
        }
    }

}
